package com.cl.edu.web.teacher;

import java.util.Date;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.cl.core.orm.Page;
import com.cl.edu.entity.Ts;
import com.cl.edu.service.teacher.TsManager;
import com.opensymphony.xwork2.ActionSupport;

@Results( { @Result(name = "success", location = "tc_ts.jsp")})
public class TsAction extends ActionSupport{
	@Autowired
	private TsManager tsManager;
	
	private Long id;//教员id
	
	private String content;	//建议内容
	
	private Page<Ts> page = new Page<Ts>(3);
	
	/**
	 * 进入页面时查看投诉本人的以往投诉建议记录
	 */
	public String execute() throws Exception{
		if (!page.isOrderBySetted()) {
			page.setOrderBy("createTime");
			page.setOrder(Page.DESC);
		}
		page = tsManager.getTsPage(page,id);
		return "success";
	}
	
	/**
	 * 新增投诉建议
	 * @return
	 * @throws Exception
	 */
	public String save() throws Exception {
		Ts ts = new Ts();
		ts.setFromId(id.intValue());
		ts.setContent(content);
		ts.setCreateTime(new Date());
		ts.setIsReplay(0);
		tsManager.addTs(ts);
		addActionMessage("您的投诉已提交，我们会尽快处理，请您时刻关注我们!");
		return execute();
	}
	

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Page<Ts> getPage() {
		return page;
	}

	public void setPage(Page<Ts> page) {
		this.page = page;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
}
